package app.tcp;

import game.components.AppUtilities;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import app.ui.MainFrame;

public class TCP_Utilities implements Runnable {
	private MainFrame mFrame;
	private ObjectInputStream input;

	public TCP_Utilities(MainFrame mFrame) {
		super();
		this.mFrame = mFrame;
	}

	public void sentObject(ObjectOutputStream output) {
		try {
			output.writeObject(mFrame.getAppUtilities());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	protected synchronized void readObject() {
		try {
			AppUtilities appUtilities = (AppUtilities) input.readObject();
			mFrame.setAppUtilities(appUtilities);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void run() {
		while (input != null) {
			this.readObject();
		}
	}

	public ObjectInputStream getInput() {
		return input;
	}

	public void setInput(ObjectInputStream input) {
		this.input = input;
	}
}
